home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-05-26 | 2.8 KB | 128 lines |
- import java.io.*;
-
- /**
- * <code>DocumentHeader</code> class is used to read/write PilotDoc header records
- * NOTE: Information about the various fields was taken from <a href="http://www.concentric.net/~n9mtb/cq/doc/format.html">CQ Codeworks</a>
- * @author Jeffrey A. Krzysztow
- * @author Pat Beirne
- * @version 1.1
- */
- public class DocumentHeader {
- /**
- * constant to indicate PilotDoc is uncompressed
- * @since 1.0
- */
- public final static short UNCOMPRESSED = 1;
-
- /**
- * constant to indicate PilotDoc is compressed
- * @since 1.0
- */
- public final static short COMPRESSED = 2;
-
- /**
- * size of text record
- * @since 1.0
- */
- public final static short textRecordSize = 4096;
-
- /**
- * version of PilotDoc
- * @since 1.0
- */
- public short version = 0; // 2 Word 1=plain text, 2=compressed
-
- /**
- * spare (unknown)
- * @since 1.0
- */
- public short spare = 0; // 2 Word
-
- /**
- * length of uncompressed PilotDoc
- * @since 1.0
- */
- public int storyLen = 0; // 4 DWord in bytes, when decompressed
-
- /**
- * number of PilotDoc records
- * @since 1.0
- */
- public short numRecords = 0; // 2 Word text records
-
- /**
- * uncompressed text record size
- * @since 1.0
- */
- public short recordSize = textRecordSize; // 2 Word usually 0x1000
-
- /**
- * currently viewed position in the document
- * not used by all readers
- * @since 1.0
- */
- public int position = 0; // 4 DWord
- // 16 bytes for Document Header
-
- /**
- * The size of the DocumentHeader in bytes
- * @returns the number of bytes in the DocumentHeader
- * @since 1.0
- */
- public static int getSize() {
- return(16);
- }
-
- /**
- * Reads the DocumentHeader from the DataInput
- * @param the DataInput to read from
- * @since 1.0
- */
- public void read(DataInput di) throws IOException {
- version = di.readShort();
- spare = di.readShort();
- storyLen = di.readInt();
- numRecords = di.readShort();
- recordSize = di.readShort();
- position = di.readInt();
- }
-
- /**
- * Writes the DocumentHeader to the DataInput
- * @param the DataInput to write to
- * @since 1.0
- */
- public void write(DataOutput out) throws IOException {
- out.writeShort(version);
- out.writeShort(spare);
- out.writeInt(storyLen);
- out.writeShort(numRecords);
- out.writeShort(recordSize);
- out.writeInt(position);
- }
-
- /**
- * indicates whether the document is compressed or not
- * @since 1.1
- */
- public boolean isCompressed() {
- return version == COMPRESSED;
- }
-
- /**
- * override Object.toString()
- * @since 1.0
- */
- public String toString() {
- return ">> DocumentHeader <<"
- + "\nversion = " + version
- + "\nspare = " + spare
- + "\nstoryLen = " + storyLen
- + "\nnumRecords = " + numRecords
- + "\nRecSize = " + recordSize
- + "\nposition = " + position;
- }
-
- }
-
-